#![allow(dead_code)]
use chrono::NaiveDate;
use sqlx::sqlite::SqlitePoolOptions;

#[derive(sqlx::FromRow, Debug)]
struct Student {
    id: u64,
    name: String,
    age: u8,
    admission_data: NaiveDate
}
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
    let pool = SqlitePoolOptions::new()
        .connect("sqlite://sqlx-cli-lib/data.db").await?;
    
    // let _ = sqlx::query("insert into student (id, name, age, admission_data) values (?, ?, ?, ?)")
    //     .bind(1)
    //     .bind("sjt".to_string())
    //     .bind(18)
    //     .bind(NaiveDate::from_ymd_opt(2021, 1, 1).unwrap())
    //     .execute(&pool)
    //     .await?;
    let students = sqlx::query_as::<_, Student>("SELECT * FROM student WHERE name = ?")
        .bind("sjt")
        .fetch_all(&pool)
        .await?;
    
    println!("{:#?}", students);
    Ok(())
}